package com.wgts.wgts.mvp.view.activity.search;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wgts.wgts.R;

import java.util.List;

/**
 * 搜索历史记录和热门
 */
public class SearchHistoryHotAdapter extends RecyclerView.Adapter<SearchHistoryHotAdapter.SearchViewHolder> {

    private List<String> srcDate;

    private Context context;

    private OnItemClick onItemClick;

    public SearchHistoryHotAdapter(List<String> srcDate, Context context){

        this.srcDate = srcDate;
        this.context = context;

    }

    public void setOnItemClick(OnItemClick onItemClick){
        this. onItemClick = onItemClick;
    }


    @NonNull
    @Override
    public SearchViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new SearchViewHolder(LayoutInflater.from(context).inflate(R.layout.search_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull SearchViewHolder searchViewHolder, final int i) {
        searchViewHolder.itme.setText(srcDate.get(i));
        searchViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onItemClick != null){
                    onItemClick.onClick(v, i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return srcDate.size();
    }

    public class SearchViewHolder extends RecyclerView.ViewHolder {

        public TextView itme;
        public View itemView;

        public SearchViewHolder(@NonNull View itemView) {
            super(itemView);
            this.itemView = itemView;
            itme = itemView.findViewById(R.id.tv_item);
        }
    }

    public interface OnItemClick{
        void onClick(View view, int ponstion);
    }
}
